/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package br.edu.disciplina;

import br.edu.curso.Curso;
import br.edu.util.GenericDAO;
import br.edu.util.HibernateUtil;
import java.util.List;
import org.hibernate.criterion.Restrictions;

/**
 *
 * @author 'Pedro
 */
public class DisciplinaDAO extends GenericDAO<Disciplina>{
    
    public DisciplinaDAO(){
        super(Disciplina.class);
    }

    public Disciplina pesquisarCodigo(Integer valueOf) {
        Disciplina disciplina;
        setSessao(HibernateUtil.getSessionFactory().openSession());
        setTransacao(getSessao().beginTransaction());
        disciplina = (Disciplina) getSessao().createCriteria(Disciplina.class).add(Restrictions.eq("id", valueOf)).uniqueResult();
        getSessao().close();
        return disciplina;
    }

    public List<Disciplina> pesquisarDescricaoLike(String text) {
        List<Disciplina> disciplinas=null;
        setSessao(HibernateUtil.getSessionFactory().openSession());
        setTransacao(getSessao().beginTransaction());
        disciplinas = (List<Disciplina>) getSessao().createCriteria(Disciplina.class).add(Restrictions.ilike("descricao", text)).list();
        getSessao().close();
        return disciplinas;
    }

    public boolean salvar(Disciplina disciplina) {
        if(disciplina.getId()==0){
            adicionar(disciplina);
        } else {
            atualizar(disciplina);
        }
        return true;
    }
    
}
